package com.ytkj.ygAssist.main;

import com.ytkj.ygAssist.tools.JFrameListeningInterface;

public class YunGouServer {
	/*
	 * 提前揭晓：根据商品ID和期数来查询
	 */
	public static void setForeknow(String goodsID, String period, String EIdx,
			JFrameListeningInterface foreknowInterface) {
		ForeknowServer.getForeknow(goodsID, period, EIdx, foreknowInterface);
	}

	/*
	 * 马上开奖
	 */
	public static void setNowWinning(String goodsID, String period, JFrameListeningInterface foreknowInterface) {
		NowWinningServer.getNowWinningServer(goodsID, period, foreknowInterface);
	}

	/*
	 * 监控商品
	 */
	public static void setYunGouRemind(final boolean isListener, final int remindIndex, final String goodsID, final String listenerIndex,
									   final JFrameListeningInterface foreknowInterface) {
		new Thread(new Runnable() {
			public void run() {
				YunGouRemindServer yunGouRemindServer = YunGouRemindServer.getYunGouRemindServer(remindIndex);
				if (isListener) {
					yunGouRemindServer.setRemindServer(goodsID, listenerIndex, foreknowInterface);
				} else {
					yunGouRemindServer.stopRemindServer();
				}
			}
		}).start();
	}

	/*
	 * 智能监听
	 */
	public static void setIntelligentMonitoring(final boolean isListener, final String goodsID, final String EIdx,
												final JFrameListeningInterface foreknowInterface) {
		new Thread(new Runnable() {
			public void run() {
				try {
					IntelligentMonitoringServer intelligentMonitoringServer = IntelligentMonitoringServer
							.getIntelligentMonitoringServer();
					if (isListener) {
						intelligentMonitoringServer.setRemindServer(goodsID, EIdx, foreknowInterface);
					} else {
						intelligentMonitoringServer.stopRemindServer();
					}
				} catch (Exception e) {
					foreknowInterface.setFrameText("setGoodsNameError", null);
				}
			}
		}).start();
	}

	/*
	 * 走势分析：根据商品ID和期数来查询
	 */
	public static void setTrendChart(String goodsID, String EIdx, JFrameListeningInterface foreknowInterface) {
		TrendChartServer.getTrendChart(goodsID, EIdx, foreknowInterface);
	}

	/*
	 * 云购登录
	 */
	public static void yunGouLogin(final boolean isLogin, final String name, final String pwd,
								   final JFrameListeningInterface foreknowInterface) {
		new Thread(new Runnable() {
			public void run() {
				if (isLogin) {
					if (YunGouLoginServer.getUserServer().userLogin(name, pwd)) {
						foreknowInterface.setFrameText("loginSucceed", name);
						String balance = YunGouLoginServer.getUserServer().getUserBalance();
						foreknowInterface.setFrameText("loginBalance", balance);
					} else {
						foreknowInterface.setFrameText("loginError", null);
					}
				} else {
					YunGouLoginServer.getUserServer().userLogout();
					foreknowInterface.setFrameText("logout", null);
				}
			}
		}).start();
	}

	/*
	 * 购买
	 */
	public static void buyGoods(final String codeID, final String buyNum, final JFrameListeningInterface foreknowInterface) {
		new Thread(new Runnable() {
			@Override
			public void run() {
				YunGouLoginServer.getUserServer().buyGoods(codeID, buyNum, foreknowInterface);
			}
		}).start();
	}

	/*
	 * 登录助手
	 */
	public static void loginAssist(final String userid, final String password, final JFrameListeningInterface foreknowInterface) {
		new Thread(new Runnable() {
			public void run() {
				AssistServer.loginAssist(userid, password, foreknowInterface);
			}
		}).start();
	}
}